package org.itolik.mppextractor;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.Statement;
import java.sql.ResultSet;

public class msql2 {
	String ServerAaddress = "192.168.0.196";
	String DBname = "mppdata";
	String user = "ruser";
	String password = "ruser";
    Connection conn = null;
	Statement stmt = null; // Create statement for our quary.
	ResultSet rs = null; 	// Result variable.
	
	public void dbConnect (){
		
		try {
		    conn =
		       DriverManager.getConnection("jdbc:mysql://"+ ServerAaddress +"/"+DBname +
		                                   "?user="+user+"&password="+password);
		    
		    //check connection status.
		    if (conn != null) {
				System.out.println("You made it, take control your database now!");
				
				
				try {
				    stmt = conn.createStatement();
				    rs = stmt.executeQuery("SELECT * FROM Source");

				    // or alternatively, if you don't know ahead of time that
				    // the query will be a SELECT...

				    if (stmt.execute("SELECT * FROM Source")) {
				        rs = stmt.getResultSet();
				    }
				    rs.next();
				    rs.next();
				    String firstName = rs.getString("username");
				    System.out.println(firstName);
				    
				}
				catch (SQLException ex){
				    // handle any errors
				    System.out.println("SQLException: " + ex.getMessage());
				    System.out.println("SQLState: " + ex.getSQLState());
				    System.out.println("VendorError: " + ex.getErrorCode());
				}
				finally {
				    // it is a good idea to release
				    // resources in a finally{} block
				    // in reverse-order of their creation
				    // if they are no-longer needed

				    if (rs != null) {
				        try {
				            rs.close();
				        } catch (SQLException sqlEx) { } // ignore

				        rs = null;
				    }

				    if (stmt != null) {
				        try {
				            stmt.close();
				        } catch (SQLException sqlEx) { } // ignore

				        stmt = null;
				    }
				}
			} else {
				System.out.println("Failed to make connection!");
			}
		    
		   //Catch error for connection
		} catch (SQLException ex) {
		    // handle any errors
		    System.out.println("SQLException: " + ex.getMessage());
		    System.out.println("SQLState: " + ex.getSQLState());
		    System.out.println("VendorError: " + ex.getErrorCode());
		}
		
	}
	
	

	
		
		
		
	
		
}



